/* rccmf.i - Shipper Workbench - Internal procedure create cmf message        */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.4.1.2 $                                                           */
/*V8:ConvertMode=NoConvert                                                    */
/* REVISION: 8.6    LAST MODIFIED: 12/29/96   BY: *K022* Kieu Nguyen          */
/* REVISION: 8.6    LAST MODIFIED: 05/09/97   BY: *K0CZ* Kieu Nguyen          */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan           */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown           */
/* $Revision: 1.4.1.2 $    BY: Jean Miller    DATE: 03/22/01 ECO: *P008*        */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{gpcmf.i}

PROCEDURE create-so-cmf:
/*--------------------------------------------------------------------
  Purpose:
  Parameters:
  Notes:
---------------------------------------------------------------------*/
   define input parameter sod_recid as recid no-undo.

   /* LOCAL VARIABLES */
   define variable v_doc_type like cmf_doc_type .
   define variable v_doc_ref  like cmf_doc_ref .
   define variable v_add_ref  like trq_add_ref .
   define variable v_msg_type like trq_msg_type.
   define variable v_transnbr like cmf_trans_nbr initial 0.
   define variable v_totpik   like sod_qty_pick.
   define variable v_trqid    like trq_id.
   define variable v_isqueued as logical initial yes.

   find sod_det where recid(sod_det) = sod_recid no-lock no-error.
   if not available sod_det then
      return.

   find so_mstr where so_nbr = sod_nbr no-lock no-error.
   if not available so_mstr then
      return.

   if sod_qty_ship = 0 then do:

      v_totpik = sod_qty_pick.

      find cmf_mstr where cmf_doc_type = "SO"
                      and cmf_doc_ref  = sod_nbr
                      and cmf_status   = "1"
      no-lock no-error.

      if available cmf_mstr and v_isqueued
      then do:

         assign
            v_doc_type = cmf_doc_type
            v_doc_ref  = cmf_doc_ref
            v_transnbr = cmf_trans_nbr
            v_add_ref  = ""
            v_msg_type = "ORDRSP-S"
            v_trqid = 0.

         {gprun.i ""gpquedoc.p""
            "(input-output v_doc_type,
              input-output v_doc_ref,
              input-output v_add_ref,
              input-output v_msg_type,
              input-output v_trqid,
              input no)" }

         if v_trqid <> 0 then
            return. /* TRQ_MSTR not unqueued */

         v_isqueued = no.

      end.

      if not available cmf_mstr then do:
         assign
            v_doc_type = "SO"
            v_doc_ref  = sod_nbr
            v_add_ref  = ""
            v_transnbr = 0 /* Initialized for the next creation */
            v_msg_type = "ORDRSP-S".
      end.

      run cmd_chg_sod
         (input sod_nbr,
          input sod_line,
          input "sod_qty_pick",
          input string(v_totpik),
          input so_po,
          input-output v_transnbr).

      if v_transnbr = -1 then next.

   end.

   if v_transnbr > 0 then do:

      v_trqid = 0.

      {gprun.i ""gpquedoc.p""
         "(input-output v_doc_type,
           input-output v_doc_ref,
           input-output v_add_ref,
           input-output v_msg_type,
           input-output V_trqid,
           input Yes)" }
   end.

END PROCEDURE.
